package www.openteam.com.presenter;

import android.util.Log;

import www.openteam.com.bean.Result;
import www.openteam.com.bean.User;
import www.openteam.com.model.UserModel;
import www.openteam.com.model.UserModelImpl;
import www.openteam.com.view.UserView;

/**
 * Created by kylin on 2016/7/25.
 */
public class UserPresenterImpl implements UserPresenter,UserModelImpl.UserOnListener {

    /**
     * UserModel和UserView都是通过接口来实现，这就Java设计原则中依赖倒置原则使用
     */
    private UserModel userModel;
    private UserView userView;

    public UserPresenterImpl(UserView userView) {
        this.userModel = new UserModelImpl(this);
        this.userView = userView;
    }

    @Override
    public void getUserData(int pageSize) {
        userModel.getUserData(pageSize);
    }

    @Override
    public void login(String name, String pass) {
        userModel.login(name,pass);
    }

    @Override
    public void onSuccess(User u) {
        userView.loadUserData(u);

        Log.d("-------", "onSuccess() called with: " + "s = [" + u.toString() + "]");
    }

    @Override
    public void onLoginSuccess(Result result) {
        userView.checkStatue(result);
    }

    @Override
    public void onLoginFailure(Throwable e) {
        userView.hideProgress();
        Log.d("-------","onFailure"+e.getMessage());
    }

    @Override
    public void onFailure(Throwable e) {
        userView.hideProgress();
        Log.d("-------","onFailure"+e.getMessage());
    }
}
